<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    table{
      width: 100%;
      border-collapse: collapse;
    }
    td,th{
      text-align: center;
      padding: 10px 0;
      border: 1px solid #ccc;
    }
  </style>
</head>
<body>
  <div id="app">
    <lx-table :list = 'list' :cols = 'cols'></lx-table>
  </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
  new Vue({
    el:'#app',
    components:{
      'lx-table':{
        props:['cols','list'],
        template:`
        <table>
      <thead>
        <tr>
          <th v-for = 'item in cols'>{{item.label}}</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="item in list">
          <td v-for = 'key in cols'> {{item[key.keys]}}</td>
        </tr>
      </tbody>
    </table>
        `
      }
    },
    methods:{
      
    },
    data() {
      return {
        cols:[
          {
            label:'编号',
            keys:'id'
          },
          {
            label:'姓名',
            keys:'name'
          },
          {
            label:'年龄',
            keys:'age'
          },
        ],
        list:[
          {
            id:1,
            name:'刘鑫',
            age:18
          },
          {
            id:2,
            name:'刘鑫22',
            age:18
          },
          {
            id:3,
            name:'刘鑫bb',
            age:18
          }
        ]
        
      }
    },
  })
</script>
</html>